{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "489e9f53",
   "metadata": {},
   "outputs": [],
   "source": [
    "import sys\n",
    "import os\n",
    "import cv2\n",
    "\n",
    "import matplotlib.pyplot as plt\n",
    "%matplotlib inline"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "c33ef483",
   "metadata": {},
   "outputs": [],
   "source": [
    "def im_show(image):\n",
    "    plt.imshow(image)\n",
    "    plt.show()\n",
    "    \n",
    "def read_label_in(label_path):\n",
    "    labels = []\n",
    "    with open(label_path, 'r') as fin:\n",
    "        for line in fin.readlines():\n",
    "            items = line.strip().split()\n",
    "            items = map(float, items)\n",
    "            labels.append(items)\n",
    "    return labels"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "2d98a38b",
   "metadata": {},
   "outputs": [],
   "source": [
    "#soccer_root = '/media/avs/39efc736-bf77-4764-85e3-1a91d963a099/huangying/datas/cba_multiview/train_dst_crop_640'\n",
    "#im_name  = 'cba_0_view_0422_0'\n",
    "ball_root = '/media/avs/39efc736-bf77-4764-85e3-1a91d963a099/huangying/datas/third_basket_2560'\n",
    "im_name = 'third_view_32_0131_0'\n",
    "img = cv2.imread(os.path.join(ball_root, 'images', '{}.jpg'.format(im_name)))\n",
    "labels = read_label_in(os.path.join(ball_root, 'labels', '{}.txt'.format(im_name)))\n",
    "\n",
    "img_h, img_w, c = img.shape\n",
    "for label in labels:\n",
    "    l_name, x_center, y_center, w, h = label\n",
    "    left = (x_center-w/2)*img_w\n",
    "    top = (y_center-h/2)*img_h\n",
    "    right = (x_center+w/2)*img_w\n",
    "    bottom = (y_center+h/2)*img_h\n",
    "    print(\"label %d %d %d %d \" % (left, top, right, bottom) )\n",
    "    left, top, right, bottom = int(left), int(top), int(right), int(bottom)\n",
    "    cv2.rectangle(img, (left, top), (right, bottom), (255, 0, 0), 2)\n",
    "img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)\n",
    "im_show(img)    \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "3ee6afe6-01a7-48fa-8a6d-1897dd887e15",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
